package com.aizuda.boot.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OpenApi 配置信息
 *
 * @author 青苗
 * @since 2023-07-19
 */
@OpenAPIDefinition
@Configuration
public class OpenApiConfiguration {

    @Bean
    public OpenAPI springShopOpenAPI() {
        final String loginToken = "accessToken";
        return new OpenAPI().info(new Info().title("合同管理系统 Boot API")
                        .description("赤子城合同管理系统！")
                        .version("v1.0.0")).externalDocs(new ExternalDocumentation()
                        .description("赤子城合同管理系统")
                )
                .components(new Components().addSecuritySchemes(loginToken, new SecurityScheme()
                        .type(SecurityScheme.Type.APIKEY)
                        .in(SecurityScheme.In.HEADER)
                        .name(loginToken)))
                .addSecurityItem(new SecurityRequirement().addList(loginToken));
    }

    @Bean
    public GroupedOpenApi v1Api() {
        return GroupedOpenApi.builder().group("v1").pathsToMatch("/v1/**").build();
    }

    @Bean
    public GroupedOpenApi authApi() {
        return GroupedOpenApi.builder().group("系统授权")
                .pathsToMatch("/auth/**", "/oauth/**")
                .build();
    }

    @Bean
    public GroupedOpenApi sysApi() {
        return GroupedOpenApi.builder().group("系统管理").pathsToMatch("/sys/**").build();
    }


    @Bean
    public GroupedOpenApi fileApi() {

        return GroupedOpenApi.builder().group("文件管理").packagesToScan("com.aizuda.boot.modules.file").build();
    }

    @Bean
    public GroupedOpenApi thirdApi() {

        return GroupedOpenApi.builder().group("三方对接").packagesToScan("com.aizuda.boot.modules.third").build();
    }


    @Bean
    public GroupedOpenApi contractApi() {
        return GroupedOpenApi.builder().group("业务").packagesToScan("com.aizuda.boot.modules.business").build();
    }

    @Bean
    public GroupedOpenApi mobileApi() {
        return GroupedOpenApi.builder().group("移动端").packagesToScan("com.aizuda.boot.modules.mobile").build();
    }
}

